﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;

namespace EasySL.Server
{
    class Program
    {
        public static void Main(string[] args)
        { 
            string binDir = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName;
            string journalDir = Path.Combine(binDir, "Journal");

            bool runAsConsole = Environment.UserInteractive;
             ServerApp app = new ServerApp();

            if (runAsConsole)
            {
                InitJournal(true, journalDir);
                app.Run();
            }
            else
            {
                InitJournal(false, journalDir);
                WindowsService service = new WindowsService(app);
                service.Run();
            }
        }

        static void InitJournal(bool logToConsole, string journalDir)
        {
            if (!string.IsNullOrEmpty(journalDir))
            {
                if (!Directory.Exists(journalDir))
                {
                    Directory.CreateDirectory(journalDir);
                }
            }

            Logger.Init(logToConsole, journalDir);
        }
    }
}
